package movee.domain.exception;

import org.springframework.lang.Nullable;
import org.springframework.util.StringUtils;

import java.util.Collection;

/**
 * compare two topo domain entity field value
 *
 * @author movee
 */
public final class AppAssert {

    private AppAssert() { }

    public static void isTrue(boolean expression, AppStatusCode code, String message) {
        if (!expression) {
            throw new AppException(code, message);
        }
    }

    public static void notNull(@Nullable Object object, AppStatusCode code, String message) {
        if (object == null) {
            throw new AppException(code, message);
        }
    }

    public static void hasText(@Nullable String text, AppStatusCode code, String message) {
        if (!StringUtils.hasText(text)) {
            throw new AppException(code, message);
        }
    }

    public static void notEmpty(Collection<?> collection, AppStatusCode code, String message) {
        if (collection == null || collection.isEmpty()) {
            throw new AppException(code, message);
        }
    }

    public static void mustEmpty(Collection<?> collection, AppStatusCode code, String message) {
        if (collection != null && !collection.isEmpty()) {
            throw new AppException(code, message);
        }
    }

    public static void mustEmpty(String text, AppStatusCode code, String message) {
        if (!StringUtils.isEmpty(text)) {
            throw new AppException(code, message);
        }
    }
}

